﻿@model Jb.Web.ViewModels.UtilityModels.ListConfig
@using Jb.Web.Utility;
@using Jb.Common.Extensions;
@using Jb.Common.DB;

@{
    String pageTitle = "Cover Letter List";
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = JobSeekerMenu.Coverletter;
}

<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>
        Add, Edit and manage your Cover Letters.
    </div>
</div>
<div class="jb-page-content">    
    <a href="@Url.JobSeekerUrl("Edit", "CoverLetter")">Add New Cover Letter</a>
    <div id="divMessage"></div>

    @foreach(System.Data.DataRow _Row in Model.DataSource.Rows){
        int _ID = NullHandler.GetInt(_Row["ID"]);
        bool _IsDefault = NullHandler.GetBoolean(_Row["IsDefault"]);
        String _EditUrl = Url.JobSeekerUrl(String.Format("Edit/{0}", _ID), "CoverLetter");
    <div class="jb-job">
        <div>
            <h2><small><a href="@(_EditUrl)">@_Row["Title"]</a></small></h2>                
        </div>            
        <div>            
            @if (_IsDefault){
                <span class="label label-success">Default</span>
            }
            else {                
                <span class="label label-warning">Not Default</span>
            }
        </div>
        <div class="para">
            @Html.Raw(WebUtil.FormatText(NullHandler.GetString(_Row["Application"])))
        </div>
        <div>            
            <a href="@(_EditUrl)" class="btn btn-primary btn-mini"><i class="icon-edit icon-white"></i> Edit</a>
            <a href="javascript:void(0);" class="btn btn-mini" onclick="ConfirmDeleteCover(@(_ID), this)"><i class="icon-remove"></i> Delete</a>
        </div>
    </div>
    }    
</div>

@*Delete Confirmation Modal Popup Section Start*@
<div id="divConfirmDialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="divPhotoEditModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
        <h4 id="myModalLabel">Confirm Delete</h4>
    </div>
    <div class="modal-body jb-inline-label">            
        <div id="divModalMesssage">Are sure you want to delete this Coverletter?</div>
    </div>
    <div class="modal-footer">               
        <button type="button" class="btn btn-primary" onclick="DeleteFromFavoriteJob();"><i class="icon-remove icon-white"></i> Remove</button>
        <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i> Cancel</button>
    </div>
</div>
@*Delete Confirmation Modal Popup Section End*@

@section PageHeadSection
{
<style type="text/css">
    .jb-job{padding-left:0px; padding-right:0px;}
</style>
}

@section JavaScriptPlaceHolder
{
<script language="javascript" type="text/javascript">
    var _DeleteAnchor = null, _DeleteID = 0;
    function ConfirmDeleteCover(id, anchor) {
        _DeleteAnchor = anchor; _DeleteID = id;
        $('#divConfirmDialog').modal({ show: true });
    }
    function DeleteFromFavoriteJob() {
        $('#divConfirmDialog').modal('hide');
        ShowLoadingAnimation(false);
        Ajax('@Url.JobSeekerUrl("Delete", "Coverletter")', 'id=' + _DeleteID, function (result) {
            HideLoadingAnimation();
            var status = (parseInt(result));
            if (status > 0) {
                $(_DeleteAnchor).parent().parent().slideUp('slow');                
            }
            $('#divMessage').html(BuildDeleteMessage(status));
        });
    }
    function BuildDeleteMessage(status) {
        var html = '';
        if (status > 0)
            html = SuccessMessageBox("Success! The Coverletter deleted successfully.");
        else if (status == -1)
            html = WarningMessageBox("Sorry! We couldn't delete this Coverletter.", "Invalid Request");
        else if (status == -2)
            html = WarningMessageBox("Sorry! The requested Coverletter was not found to delete.");
        return html;
    }
</script>
}

